package logic

import (
	"context"
	"fmt"
	"yk/models/mysql"

	"yk/ykrpc/internal/svc"
	"yk/ykrpc/ykrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowLogic) Show(in *ykrpc.YkShowRequest) (*ykrpc.YkShowResponse, error) {
	// todo: add your logic here and delete this line
	var yk mysql.Phone
	mysql.DB.Debug().Where("id =?", in.Id).Find(&yk)
	if yk.ID == 0 {
		return nil, fmt.Errorf("商品不存在")
	}
	return &ykrpc.YkShowResponse{
		Name:    yk.Name,
		Num:     int64(yk.Num),
		Address: yk.Address,
		Id:      int64(yk.ID),
	}, nil
}
